package com.example.dessert.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.dessert.dao.CartMapper;
import com.example.dessert.entity.Cart;
import com.example.dessert.service.CartService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName: CartServiceImpl
 * @Description:
 * @Author li
 * @Date 2022/1/14
 * @Version 1.0
 */
@Service
public class CartServiceImpl implements CartService {

    @Resource
    private CartMapper cartMapper;

    @Override
    public Long storeCart(Cart cart) {

        cartMapper.insert(cart);
        return  cart.getId();

    }

    @Override
    public int cancelCart(Long id) {

        return cartMapper.deleteById(id);

    }

    @Override
    public int updateCartById(Cart cart) {

        return cartMapper.updateById(cart);

    }

    @Override
    public Cart queryCartInfo(Long userId,Long productId,Long specId) {

        QueryWrapper<Cart> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",userId)
               .eq("product_id",productId)
               .eq("spec_id",specId);
        return cartMapper.selectOne(wrapper);

    }


    @Override
    public List<Cart> queryCartList(Long userId) {

        return cartMapper.queryCartList(userId);

    }

    @Override
    public List<Cart>  queryCartListByIds(Long userId,String ids){
        return cartMapper.queryCartListByIds(userId,ids);
    }

}
